﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class UIPRG : ViewBase
    {
        public VICC_PROGDEF TMV
        {
            get
            {
                return (VICC_PROGDEF)MV;
            }
        }

        #region ==PRGCT===========
        public static readonly DependencyProperty PRGCTProperty = DependencyProperty.Register("PRGCT",
            typeof(string), typeof(UIPRG),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPRGCTChanged));
        public string PRGCT
        {
            get
            {
                return (string)GetValue(PRGCTProperty);
            }
            set
            {
                SetValue(PRGCTProperty, value); 
            }
        }
        private static void OnPRGCTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIPRG;
            if (src != null)
            {
                src.PRGCT = (string)e.NewValue;
            }
        }
        #endregion

        #region ==PROG===========
        public static readonly DependencyProperty PROGProperty = DependencyProperty.Register("PROG",
            typeof(string), typeof(UIPRG),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPROGChanged));
        public string PROG
        {
            get
            {
                return (string)GetValue(PROGProperty);
            }
            set
            {
                SetValue(PROGProperty, value);
                OnPROGChg(value);
            }
        }
        private static void OnPROGChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIPRG;
            if (src != null)
            {
                src.PROG = (string)e.NewValue;
            }
        }
        #endregion
        #region ==CONTROLS===========
        public static readonly DependencyProperty CONTROLSProperty = DependencyProperty.Register("CONTROLS",
            typeof(string), typeof(UIPRG),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnCONTROLSChanged));
        public string CONTROLS
        {
            get
            {
                return (string)GetValue(CONTROLSProperty);
            }
            set
            {
                SetValue(CONTROLSProperty, value);
                OnCONTROLSChg(value);
            }
        }
        private static void OnCONTROLSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIPRG;
            if (src != null)
            {
                src.CONTROLS = (string)e.NewValue;
            }
        }
        #endregion

        #region ==REMARK===========
        public static readonly DependencyProperty REMARKProperty = DependencyProperty.Register("REMARK",
            typeof(string), typeof(UIPRG),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnREMARKChanged));
        public string REMARK
        {
            get
            {
                return (string)GetValue(REMARKProperty);
            }
            set
            {
                SetValue(REMARKProperty, value);
                OnREMARKChg(value);
            }
        }
        private static void OnREMARKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIPRG;
            if (src != null)
            {
                src.REMARK = (string)e.NewValue;
            }
        }
        #endregion


      
        public UIPRG()
        { 
        }


        public void Insert(DataRow dwFC)
        {
            ((VICC_PROGDEF)MV).DeleteICC_PROGDEF(dwFC, 1);
            ((VICC_PROGDEF)MV).InsertICC_PROGDEF(dwFC, app.company);
            TBMain.Rows.InsertAt(dwData, 0);
        } 
        
        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            ((VICC_PROGDEF)MV).DeleteICC_PROGDEF(dwMaster, 1);
            string filter = "ROWNID='" + dwMaster["ROWNID"].ToString() + "'";
            DataRow[] rows = TBMain.Select(filter);
            vwMaster.View.MoveCurrentTo(-1);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
            TBMain.AcceptChanges();
            base.DeleteCommand(sender, e);
        }
         
        public virtual void OnPROGChg(string value)
        {
            
        }
        public virtual void OnCONTROLSChg(string value)
        {

        }
        public virtual void OnREMARKChg(string value)
        {

        }
        

        public void ResetSeq(object sender, RoutedEventArgs e)
        {
            VSDDAT.SD22.RESETSEQ("0022", "  ", "PRSEQ", 1);
            ((VICC_PROGDEF)MV).DeleteICC_PROGDEF(null, 0);
            foreach (DataRow row in TBMain.Rows)
            {
                ((VICC_PROGDEF)MV).DeleteICC_PROGDEF(row, 1);
                row["ROWNID"] = VSDDAT.SD22.GETNEXT("0022", "  ", "PRSEQ", 1);
                ((VICC_PROGDEF)MV).InsertICC_PROGDEF(row, app.company);
            }
        }
    }
}
